package com.example.administrator.financialmanager.dao;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.Map;

public class DBOpenHelper extends SQLiteOpenHelper {
	private static final int VERSION = 1;// 定义数据库版本号
	private static final String DBNAME = "account.db";// 定义数据库名

	public DBOpenHelper(Context context){// 定义构造函数

		super(context, DBNAME, null, VERSION);// 重写基类的构造函数
	}

	@Override
	public void onCreate(SQLiteDatabase db){// 创建数据库

		db.execSQL("create table tb_outaccount (" +
				"_id varchar(50) primary key," +
				"money decimal," +
				"time varchar(10),"
				+ "type varchar(10)," +
				"address varchar(100)," +
				"mark varchar(200))");// 创建支出信息表
		db.execSQL("insert into tb_outaccount (_id,money,time,type,address,mark) values ('1001','20','2011-01-01','餐费','asdfafa','asfasfasf')");// 向用户表插入初始信息
		db.execSQL("insert into tb_outaccount (_id,money,time,type,address,mark) values ('1002','36','2011-01-01','应酬','asdfafa','asfasfasf')");
		db.execSQL("insert into tb_outaccount (_id,money,time,type,address,mark) values ('1003','78','2011-01-01','礼金','asdfafa','asfasfasf')");
		db.execSQL("insert into tb_outaccount (_id,money,time,type,address,mark) values ('1004','45','2011-01-01','车费','asdfafa','asfasfasf')");
		db.execSQL("insert into tb_outaccount (_id,money,time,type,address,mark) values ('1005','62','2011-01-01','其他','asdfafa','asfasfasf')");
		db.execSQL("create table tb_inaccount (" +
				"_id varchar(50) primary key," +
				"money decimal," +
				"time varchar(10),"
				+ "type varchar(10)," +
				"handler varchar(100)," +
				"mark varchar(200))");// 创建收入信息表
		db.execSQL("insert into tb_inaccount (_id,money,time,type,handler,mark) values ('10001','36','2011-01-01','兼职','asdfafa','asfasfasf')");// 向用户表插入初始信息
		db.execSQL("insert into tb_inaccount (_id,money,time,type,handler,mark) values ('10002','20','2011-01-01','工资','asdfafa','asfasfasf')");
		db.execSQL("insert into tb_inaccount (_id,money,time,type,handler,mark) values ('10003','45','2011-01-01','分红','asdfafa','asfasfasf')");
		db.execSQL("insert into tb_inaccount (_id,money,time,type,handler,mark) values ('10004','78','2011-01-01','其他','asdfafa','asfasfasf')");
		db.execSQL("insert into tb_inaccount (_id,money,time,type,handler,mark) values ('10005','62','2011-01-01','奖金','asdfafa','asfasfasf')");
		db.execSQL("create table tb_user (" +
				"username varchar(20) primary key,"+
				"password varchar(20))");// 创建用户表
		db.execSQL("insert into tb_user values('1','1')");// 向用户表插入初始信息
		db.execSQL("insert into tb_user values('wyh','123')");
		db.execSQL("insert into tb_user values('sws','123')");
		db.execSQL("insert into tb_user values('wez','123')");
//		"+
//		" ('123','123')
		db.execSQL("create table tb_flag (" +
				"_id varchar(50) primary key," +
				"flag varchar(200))");// 创建便签信息表
		db.execSQL("insert into tb_flag (_id,flag) values ('30001','asfasfasf')");
		db.execSQL("insert into tb_flag (_id,flag) values ('30002','asdfafa')");
		db.execSQL("insert into tb_flag (_id,flag) values ('30003','afagagag')");
		db.execSQL("insert into tb_flag (_id,flag) values ('30005','asdfaagasdadgfa')");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){// 覆写基类的onUpgrade方法，以便数据库版本更新
	}
}